# 读取pdf内容
# pip install pypdf2
# pip install pypdf3
# pip install pdfplumber

from PyPDF2 import PdfReader
import pdfplumber

def read_pdf1(path):
    # 获取流文件
    with open(path, 'rb') as f:
        pdf = PdfReader(f)  # 创建 pdf
        info = pdf.metadata  # 获取 pdf 中的信息
        number = len(pdf.pages)  # 获取 pdf 的页数
        for i in range(number):
            print(pdf.pages[i].extract_text)
    print()
    print(info)
    print(number)


def read_pdf2(path):
    # 获取流文件
    with pdfplumber.open(path) as pdf:
        print('\n方式一')
        num = pdf.pages
        for i in range(len(num)):
            page = pdf.pages[i]
            print(page.extract_text())

        # 方式二
        print('\n方式二')
        for page in pdf.pages:
            print(page.extract_text())


if __name__ == '__main__':
    # read_pdf1('../02.py_pdfFile/01.采购合同模板.pdf')
    read_pdf2('../02.py_pdfFile/01.采购合同模板.pdf')

